﻿using ASP;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ShopTradeOrder : Admin, IRequiresSessionState
{
    private Shop_Order _order = null;
    public string m_QuickSearch = "";
    public string m_DetailSearchType = "";
    public string m_DetailSearchName = "";
    protected string WhereStr = "";
    protected string OrderByStr = "";
    protected string linkHead = "";
    private bool m_tag = true;
    private IDbDataParameter param = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Shop_Order m_order
    {
        get
        {
            Shop_Order order;
            if (this._order == null)
            {
                this._order = new Shop_Order(this.conn);
                order = this._order;
            }
            else
            {
                order = this._order;
            }
            return order;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(21))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Order");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.BandList();
        }
    }
    protected void QueryString()
    {
        this.m_QuickSearch = Fetch.Get("QSh");
        if (this.m_QuickSearch != string.Empty && this.m_tag)
        {
            this.QuickSearch.SelectedValue = this.m_QuickSearch;
        }
        else
        {
            this.m_QuickSearch = this.QuickSearch.SelectedValue;
        }
        if (this.m_QuickSearch != "all")
        {
            string text = this.m_QuickSearch;
            switch (text)
            {
                case "standprice":
                    this.WhereStr += "and TradeType=1";
                    break;
                case "auction":
                    this.WhereStr += "and TradeType=2";
                    break;
                case "team_buy":
                    this.WhereStr += "and TradeType=3 and status!=0";
                    break;
                case "ten_day_order":
                    this.WhereStr += "and dateDiff(d,InputTime,getDate())<=10";
                    break;
                case "success":
                    this.WhereStr += "and DeliverStatus=2 and MoneyTotal<=MoneyReceipt and Status=1";
                    break;
                case "first":
                    this.WhereStr += "and TradeType=2 and Status=1";
                    break;
                case "last":
                    this.WhereStr += "and TradeType=2 and status=0";
                    break;
                case "team_beforehand":
                    this.WhereStr += "and TradeType=3 and status=0";
                    break;
            }
            this.linkHead = this.linkHead + "&QSh=" + this.m_QuickSearch;
        }
        this.m_DetailSearchType = Fetch.Get("DST");
        if (this.m_DetailSearchType != string.Empty && this.m_tag)
        {
            this.DetailSearchType.SelectedValue = this.m_DetailSearchType;
        }
        else
        {
            this.m_DetailSearchType = this.DetailSearchType.SelectedValue;
        }
        if (this.m_DetailSearchType != "")
        {
            this.m_DetailSearchName = Fetch.Get("DSN");
            if (this.m_DetailSearchName != string.Empty && this.m_tag)
            {
                this.SearchName.Text = this.m_DetailSearchName;
            }
            else
            {
                this.m_DetailSearchName = this.SearchName.Text;
            }
            if (this.m_DetailSearchName != "")
            {
                string text = this.m_DetailSearchType;
                if (text != null)
                {
                    if (!(text == "ordernum"))
                    {
                        if (!(text == "user_name"))
                        {
                            if (text == "saler_name")
                            {
                                this.WhereStr += "and ([SalerName] like '%'+ @SalerName + '%') ";
                                this.param = this.conn.CreateParameter("@SalerName", DbType.String, this.m_DetailSearchName);
                            }
                        }
                        else
                        {
                            this.WhereStr += "and ([BuyerName] like '%'+ @BuyerName + '%') ";
                            this.param = this.conn.CreateParameter("@BuyerName", DbType.String, this.m_DetailSearchName);
                        }
                    }
                    else
                    {
                        this.WhereStr += "and ([OrderFormNum] like '%'+ @OrderFormNum + '%') ";
                        this.param = this.conn.CreateParameter("@OrderFormNum", DbType.String, this.m_DetailSearchName);
                    }
                }
                string text2 = this.linkHead;
                this.linkHead = string.Concat(new string[]
				{
					text2,
					"&DST=",
					this.m_DetailSearchType,
					"&DSN=",
					base.Server.UrlEncode(this.m_DetailSearchName)
				});
            }
        }
        if (this.WhereStr != "")
        {
            this.WhereStr = "and" + this.WhereStr;
            this.WhereStr = this.WhereStr.Replace("andand", "where");
        }
    }
    protected void BandList()
    {
        int num = Fetch.GetID("page");
        if (num == 0)
        {
            num = 1;
        }
        this.QueryString();
        int maxperpage = 15;
        if (this.GridView1.PageSize != 0)
        {
            maxperpage = int.Parse(this.GridView1.PageSize.ToString());
        }
        if (this.param != null)
        {
            this.GridView1.DataSource = this.m_order.GetAllOrders(num, maxperpage, this.WhereStr, "OrderFormID desc", new IDbDataParameter[]
			{
				this.param
			});
        }
        else
        {
            this.GridView1.DataSource = this.m_order.GetAllOrders(num, maxperpage, this.WhereStr, "OrderFormID desc");
        }
        this.GridView1.DataBind();
        this.PagePanel.Text = this.m_order.GetPagePanel(this.linkHead);
    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
        this.m_tag = false;
        this.BandList();
    }
    protected void QuickSearch_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.m_tag = false;
        this.BandList();
    }
    protected void DeleteButton_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(21))
        {
            base.WriteRightErrMsg();
        }
        string text = base.Request["select_id"];
        if (text != "" && text != null)
        {
            if (this.m_order.DeleteOrder(text))
            {
                this.Delete_Tips.Text = "删除成功";
            }
            else
            {
                this.Delete_Tips.Text = "删除失败";
            }
            this.m_tag = false;
            this.BandList();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(21))
        {
            base.WriteRightErrMsg();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
        }
    }
    protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
    {
        string text = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        if (text != "" && text != null)
        {
            if (this.m_order.DeleteOrder(text))
            {
                this.Delete_Tips.Text = "删除成功";
            }
            else
            {
                this.Delete_Tips.Text = "删除失败";
            }
            this.m_tag = false;
            this.BandList();
        }
    }
}
